#!/bin/bash -x

# read config
. ../../steps.config

echo $configureswitches

if [ ! -e "configure" ] ; then
  cd config_office
  OLDCONF=../
  ./configure $configureswitches || exit $?
  cd ..
else
  ./configure $configureswitches || exit $?
fi

# put name of OOo config file created by configure in $envname
[ -f LinuxX86Env.Set.sh ] && envname=LinuxX86Env.Set.sh
[ -f LinuxX86-64Env.Set.sh ] && envname=LinuxX86-64Env.Set.sh
[ -f LinuxIntelEnv.Set.sh ] && envname=LinuxIntelEnv.Set.sh
[ -f MacOSXX86Env.Set.sh ] && envname=MacOSXX86Env.Set.sh
[ -f MacOSXPPCEnv.Set.sh ] && envname=MacOSXPPCEnv.Set.sh
[ -f SolarisX86Env.Set.sh ] && envname=SolarisX86Env.Set.sh
[ -f SolarisSparcEnv.Set.sh ] && envname=SolarisSparcEnv.Set.sh
[ -f winenv.set.sh ] && envname=winenv.set.sh

if [ -z "$envname" ] ; then
  echo Cannot determine configuration file name
  echo Please adapt the script on the buildslave
  echo cannot set CWS and Languages for build
  exit 1
fi

CWS=`echo $* | grep '\--branch' | sed -e 's/.*--branch\=//' -e 's/ .*//' | grep -v _`
if [ "$CWS" ] ; then
  echo CWS_WORK_STAMP=$CWS >> $envname
  echo CWS_WORK_STAMP_EXT=_$CWS >> $envname
  echo export CWS_WORK_STAMP CWS_WORK_STAMP_EXT >> $envname
fi

LANG=`echo $* | grep '\--languages' | sed -e 's/.*--languages\=\"//' -e 's/\".*//'`
echo WITH_LANG=\"\$WITH_LANG\ $LANG\" >> $envname
echo export WITH_LANG >> $envname

echo done

